var a = require("../../../../@babel/runtime/helpers/defineProperty"), t = require("../../../../mybehaviors/location/location"), e = getApp();

Component({
    behaviors: [ t ],
    properties: {
        params: {
            type: null
        },
        data: {
            type: null
        },
        isStore: {
            type: null
        },
        datas: {
            type: null
        },
        shopPoint: {
            type: null
        },
        shopCity: {
            type: null
        },
        is_open: {
            type: null
        }
    },
    data: {
        language: "",
        address: "",
        point: {
            lat: "",
            lng: ""
        },
        city: "",
        tab: 0,
        panelIndex: 0,
        titleName: [],
        api: "",
        dataJson: {},
        pd_classfy_arr: [],
        pd_date_arr: [],
        pd_index: 0,
        pd_date_index: 0,
        shopList0: [],
        isLoadMore0: !1,
        page0: 1,
        total_page0: 0,
        shopList1: [],
        isLoadMore1: !1,
        page1: 1,
        total_page1: 0,
        shopList2: [],
        isLoadMore2: !1,
        page2: 1,
        total_page2: 0,
        shopList3: [],
        isLoadMore3: !1,
        page3: 1,
        total_page3: 0,
        pd_date: {}
    },
    lifetimes: {
        attached: function() {
            var a = wx.getStorageSync("langIndex");
            this.setData({
                language: a.en
            }), this.data.isStore ? (this.setData({
                titleName: this.data.datas,
                point: this.data.shopPoint,
                city: this.data.shopCity
            }), this.chooseTab(" ", "business_merchant")) : (this.setData({
                titleName: this.data.data
            }), this.location());
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {},
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        location: function() {
            var a = this;
            this._getLocation(function() {
                a.chooseTab(" ", "business_merchant");
            });
        },
        toGoodBtn: function(a) {
            var t = a.currentTarget.dataset.goods_id;
            t.id ? wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + t.id
            }) : wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + t
            });
        },
        chooseTab: function(t, s) {
            var i;
            this.setData({
                tab: this.data.titleName.findIndex(function(a) {
                    return a.id == s;
                })
            }), this.setData({
                api: this.data.titleName[this.data.tab].url
            });
            var o = this.data.titleName[this.data.tab].id;
            if (this.setData((a(i = {}, "isLoadMore".concat(this.data.tab), !1), a(i, "total_page".concat(this.data.tab), 0), 
            a(i, "page".concat(this.data.tab), 1), i)), "business_merchant" === o) {
                var d = e.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
                this.setData({
                    dataJson: {
                        lng: d.lng ? d.lng : "",
                        lat: d.lat ? d.lat : "",
                        city_name: this.data.city,
                        page: this.data.page0
                    }
                });
            } else switch (o) {
              case "business_discount":
                this.setData({
                    dataJson: {
                        page: this.data.page1
                    }
                });
                break;

              case "business_coupon":
                this.setData({
                    dataJson: {
                        page: this.data.page2
                    }
                });
                break;

              case "business_goods_gift":
                this.setData({
                    dataJson: {
                        page: this.data.page3
                    }
                });
            }
            this.getList();
        },
        chooseTabData: function(a) {
            var t = 0, e = a.detail.title;
            "商家" == e ? t = 0 : "折扣" == e ? t = 1 : "优惠券" == e ? t = 2 : "礼包" == e && (t = 3), 
            this.chooseTab(" ", this.data.titleName[t].id);
        },
        getList: function() {
            var t = this;
            console.log(this.data.api);
            var s = e.getNetAddresss(this.data.api);
            e._getNetWork({
                url: s,
                data: this.data.dataJson,
                success: function(e) {
                    var s = e.data;
                    if (1 == s.result) {
                        var i;
                        if (1 === t.data.tab) t.setData({
                            pd_classfy_arr: s.data.store_category,
                            pd_date_arr: s.data.date_time
                        }), t.setData({
                            pd_category_id: s.data.store_category[0].id,
                            pd_date: s.data.date_time[0]
                        }), t.getPdData(); else t.setData((a(i = {}, "shopList".concat(t.data.tab), s.data.data), 
                        a(i, "total_page".concat(t.data.tab), s.data.last_page), i));
                        t.data["total_page".concat(t.data.tab)] <= 1 ? t.setData(a({}, "isLoadMore".concat(t.data.tab), !1)) : t.setData(a({}, "isLoadMore".concat(t.data.tab), !0));
                    } else console.log(s.msg);
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        },
        getPdData: function() {
            var a = this, t = e.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat)), s = {
                lng: t.lng,
                lat: t.lat,
                city_name: this.data.city,
                page: this.data.page1,
                week: this.data.pd_date.week_num,
                category_id: this.data.pd_category_id,
                day: this.data.pd_date.day
            }, i = e.getNetAddresss("plugin.universal-card.frontend.store-discount.privilege");
            e._getNetWork({
                url: i,
                data: s,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? (a.setData({
                        total_page1: e.data.last_page,
                        shopList1: e.data.data
                    }), a.data.total_page1 <= 1 ? a.setData({
                        isLoadMore1: !1
                    }) : a.setData({
                        isLoadMore1: !0
                    })) : a.setData({
                        isLoadMore1: !1
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        },
        toRouter: function(a) {
            var t = a.currentTarget.dataset.item;
            1 == t.specify_show ? wx.navigateTo({
                url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + t.id + "&fromHome=1"
            }) : 1 == t.store_decorate ? wx.navigateTo({
                url: "/packageG/o2o/HomeSeller/HomeSeller?store_id=" + t.id
            }) : wx.navigateTo({
                url: "/packageC/o2o/HomeSeller/HomeSeller?store_id=" + t.id
            });
        },
        toClassify: function(a) {
            var t = a.currentTarget.dataset.id, e = a.currentTarget.dataset.name;
            wx.navigateTo({
                url: "/packageC/o2o/o2oCategory/o2oCategory?id=" + t + "&city=" + this.data.city + "&point=" + JSON.stringify(this.data.point) + "&name=" + e
            });
        },
        gophone: function(a) {
            var t = a.currentTarget.dataset.mobile;
            wx.makePhoneCall({
                phoneNumber: t
            });
        },
        goToAdress: function(a) {
            var t = a.currentTarget.dataset.items.latitude, s = a.currentTarget.dataset.items.longitude, i = a.currentTarget.dataset.items.store_name, o = e.BMapTransqqMap(parseFloat(s), parseFloat(t));
            wx.openLocation({
                latitude: o.lat,
                longitude: o.lng,
                scale: 18,
                name: i
            });
        },
        getMoreList: function() {
            var t = this;
            if (this.setData(a({}, "isLoadMore".concat(this.data.tab), !1)), !(this.data["page".concat(this.data.tab)] >= this.data["total_page".concat(this.data.tab)])) {
                this.data["page".concat(this.data.tab)] = this.data["page".concat(this.data.tab)] + 1;
                var s = e.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
                switch (this.data.tab) {
                  case 0:
                    this.setData({
                        dataJson: {
                            lng: s.lng ? s.lng : "",
                            lat: s.lat ? s.lat : "",
                            city_name: this.data.city,
                            page: this.data.page0
                        }
                    });
                    break;

                  case 2:
                    this.setData({
                        dataJson: {
                            page: this.data.page2
                        }
                    });
                    break;

                  case 3:
                    this.setData({
                        dataJson: {
                            page: this.data.page3
                        }
                    });
                }
                var i = e.getNetAddresss(t.data.api);
                e._getNetWork({
                    url: i,
                    data: t.data.dataJson,
                    success: function(e) {
                        var s = e.data;
                        if (1 == s.result) {
                            var i;
                            if (1 !== t.data.tab) t.setData((a(i = {}, "shopList".concat(t.data.tab), t.data["shopList".concat(t.data.tab)].concat(s.data.data)), 
                            a(i, "total_page".concat(t.data.tab), s.data.last_page), i));
                            t.data["page".concat(t.data.tab)] >= t.data["total_page".concat(t.data.tab)] ? t.setData(a({}, "isLoadMore".concat(t.data.tab), !1)) : t.setData(a({}, "isLoadMore".concat(t.data.tab), !0));
                        } else {
                            var o;
                            t.setData((a(o = {}, "page".concat(t.data.tab), [ "page".concat(t.data.tab) ] - 1), 
                            a(o, "isLoadMore".concat(t.data.tab), !1), o));
                        }
                    },
                    fail: function(a) {
                        console.log(a);
                    }
                });
            }
        },
        pdClassfySearch: function(a) {
            var t = a.currentTarget.dataset.index, e = a.currentTarget.dataset.id;
            this.setData({
                pd_index: t
            }), this.setData({
                pd_category_id: e
            }), this.pdInitData(), this.getPdData();
        },
        pdInitData: function() {
            this.setData({
                isLoadMore1: !1,
                page1: 1,
                total_page1: 0,
                shopList1: []
            });
        },
        pdDateSearch: function(a) {
            var t = a.currentTarget.dataset.index, e = a.currentTarget.dataset.date;
            this.setData({
                pd_date_index: t
            }), this.setData({
                pd_date: e
            }), this.pdInitData(), this.getPdData();
        },
        gotoShop: function(a) {
            var t = a.currentTarget.dataset.id;
            wx.navigateTo({
                url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + t
            });
        },
        getMorePdData: function() {
            var a = this;
            if (this.setData({
                isLoadMore1: !1
            }), !(this.data.page1 >= this.data.total_page1)) {
                this.setData({
                    page1: this.data.page1 + 1
                });
                var t = e.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat)), s = {
                    lng: t.lng,
                    lat: t.lat,
                    city_name: this.data.city,
                    page: this.data.page1,
                    week: this.data.pd_date.week_num,
                    category_id: this.data.pd_category_id,
                    day: this.data.pd_date.day
                }, i = e.getNetAddresss("plugin.universal-card.frontend.store-discount.privilege");
                e._getNetWork({
                    url: i,
                    data: s,
                    success: function(t) {
                        var e = t.data;
                        if (1 == e.result) {
                            var s = e.data.data;
                            a.setData({
                                shopList1: a.data.shopList1.concat(s)
                            });
                        } else a.setData({
                            page1: a.data.page1 - 1,
                            isLoadMore1: !1
                        });
                    },
                    fail: function(a) {
                        console.log(a);
                    }
                });
            }
        },
        getCoupon: function(a) {
            var t = a.currentTarget.dataset.id, s = e.getNetAddresss("plugin.store-cashier.frontend.store.coupon-get");
            e._getNetWork({
                url: s,
                data: {
                    coupon_id: t
                },
                success: function(a) {
                    var t = a.data;
                    1 == t.result ? wx.showModal({
                        title: "提示",
                        content: "领取成功",
                        showCancel: !1,
                        success: function(a) {}
                    }) : wx.showToast({
                        title: t.msg,
                        icon: "none",
                        duration: 1500
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        },
        toGood: function(a) {
            var t = a.currentTarget.dataset.item;
            wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + t.id
            });
        }
    },
    observers: {
        datas: function() {
            this.data.datas && this.data.is_open && (this.data.isStore ? (this.setData({
                titleName: this.data.datas,
                point: this.data.shopPoint,
                city: this.data.shopCity
            }), this.chooseTab(" ", "business_merchant")) : (this.setData({
                titleName: this.data.data
            }), this.location()));
        }
    }
});